home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / utility / fsco3712.zip / EXTRACTF.EMS < prev    next >
Text File  |  1993-12-04  |  4KB  |  160 lines

  1. /*
  2.  * $VER: ExctractFile.ems 1.002 (4.12.93)
  3.  *
  4.  * $HISTORY:
  5.  *
  6.  * 04 Dec 1993 : 001.002 : Modified TEMP_FILE handling and minor changes
  7.  *                         by Flavio Stanchina 2:333/408.9fidonet.org
  8.  * 27 Nov 1993 : 001.001 : Added support for FScode by Gian Maria Calzolari
  9.  *                         2:332/502.11, 2:332/508.19
  10.  * 29 Aug 1993 : 001.000 : Updated by S. Wijman 2:2802/123@fidonet
  11.  *
  12.  */
  13.  
  14. options results
  15. signal on error
  16. signal on syntax
  17.  
  18. parse arg area_name msg_num .
  19.  
  20. if datatype( msg_num, 'N' ) ~= 1 then call Usage
  21.  
  22. if( ~show( 'l', "ems_rexx.library" ) ) then
  23. do
  24.    if( ~addlib( "ems_rexx.library", 0, -30, 0 ) )then
  25.    do
  26.       say "Could not open ems_rexx.library"
  27.       exit 10
  28.    end
  29. end
  30.  
  31. cmd.0       = 3                          /* Decoder number                */
  32. cmd.1       = 'C:UUDecode'               /* Full path to command UUDecode */
  33. cmd.2       = 'C:UUDecode'               /* Full path to command UUDecode */
  34. cmd.3       = 'C:FSCode'                 /* Full path to command FSCode   */
  35.  
  36. cmd.1.bgn   = 'begin 777'                /* What should I search for?     */
  37. cmd.2.bgn   = 'begin 644'
  38. cmd.3.bgn   = '!start'
  39.  
  40. cmd.1.end   = 'end'                      /* What will I find at the end?  */
  41. cmd.2.end   = 'end'
  42. cmd.3.end   = '!end'
  43.  
  44. cmd.1.wnum  = 3                          /* Which word is the name?       */
  45. cmd.2.wnum  = 3
  46. cmd.3.wnum  = 2
  47.  
  48. delete_name = EMS_Var_Local( 'SCRIPT_DELETE_NAME' )
  49. temp_dir    = EMS_Var_Local( 'TEMP_DIR'           )
  50. temp_file   = area_name || '.' || msg_num || '.Ext'
  51. cr          = '0a'x
  52.  
  53. /* Init of some variabiles */
  54. names.0 = 0
  55.  
  56. call EMS_Item_Alloc(     'msg', area_name, 'MSG', msg_num )
  57. call EMS_Item_Lines_Get( 'msg', 'TEXT', 'lines'           )
  58. call EMS_Item_Free(      'msg'                            )
  59.  
  60. old_dir = pragma( 'D', temp_dir )
  61.  
  62. do k = 1 to cmd.0
  63.     match = 0
  64.  
  65.     do forever
  66.         match = EMS_Search_In_Stem( 'lines', cmd.k.bgn || '#?', match )
  67.  
  68.         if match = 0 then leave
  69.  
  70.         line = lines.match
  71.         name = word( line, cmd.k.wnum )
  72.         
  73.         parse var name name1 ':' name2
  74.         if name2 ~= '' then name = name2
  75.  
  76.         parse var name name1 '/' name2 .
  77.         if name2 ~= '' then name = name2
  78.  
  79.         num       = names.0 + 1
  80.         names.0   = num
  81.         names.num = name
  82.  
  83.         if exists( name ) then do
  84.             select = EMS_Do_Request( cmd.k 'header found' || cr || 'Original FileName:' name || cr || cr || 'A file with the same name exists in the' temp_dir 'directory.' || cr || 'Should I rename it to "' || name || '.EMS" ?', 'Yes|No' )
  85.  
  86.             if select = 'Yes' then do
  87.                 name      = name'.EMS'
  88.                 names.num = name
  89.               end
  90.               else do
  91.                 select = EMS_Do_Request( 'Should I delete the existing file ?', 'Yes|No' )
  92.  
  93.                 if select = 'No' then do
  94.                     call EMS_Do_Request( 'Extracting' cmd.k 'files has been stopped.' )
  95.                     call QuitScript
  96.                 end
  97.  
  98.                 address command delete_name name
  99.             end
  100.         end
  101.  
  102.         if open( 'out', temp_file, 'W' ) ~= 1 then do
  103.             call EMS_Do_Request( 'Cannot open "' || temp_file || '" for output.' )
  104.             call QuitScript
  105.         end
  106.  
  107.         call writeln( 'out', cmd.k.bgn name )
  108.  
  109.         do forever
  110.             match = match + 1
  111.             line  = lines.match
  112.             call writeln( 'out', line )
  113.  
  114.             if left( line, length( cmd.k.end ) ) = cmd.k.end then leave
  115.         end
  116.  
  117.         call close( 'out' )
  118.  
  119.         address command cmd.k       temp_file
  120.         address command delete_name temp_file
  121.     end
  122. end
  123.  
  124. QuitScript:
  125.  
  126. call pragma( 'D', old_dir )
  127.  
  128. if names.0 > 0 then do
  129.    string = 'Check the' temp_dir 'directory for the file(s):'
  130.  
  131.    do i = 1 to names.0
  132.       string = string || cr || '   ' || names.i
  133.    end
  134.  
  135.    call EMS_Do_Request( string )
  136. end
  137.  
  138. call EMS_FreeScriptData()
  139. exit 0
  140.  
  141. Usage:
  142.  
  143. say 'Usage: ExtractFile.ems <area name> <msg num>'
  144.  
  145. call EMS_FreeScriptData()
  146. exit 0
  147.  
  148.  
  149. error:
  150. syntax:
  151.  
  152. error_text = EMS_LastError()
  153.  
  154. if error_text = '' then error_text = rc ErrorText( rc )
  155.  
  156. say '| ***BREAK: error at' sigl error_text
  157.  
  158. call EMS_FreeScriptData()
  159. exit rc
  160.